package com.zues.thread.method.join;

import com.zues.thread.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * Join 方法测试
 * t1.join();会让main线程阻塞，等待线程t1执行完，再执行main线程
 */
@Slf4j(topic = "c.JoinDemo")
public class JoinDemo1 {

    static int r = 0;

    public static void main(String[] args) {
        test1();
    }

    private static void test1() {
        log.debug("开始");
        Thread t1 = new Thread(() -> {
            log.debug("开始");
            ThreadUtil.sleep(2);
        }, "t1");
        t1.start();

        try {
            t1.join();
            ThreadUtil.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        log.debug("结束为： {}",r);
        log.debug("{} 线程结束",Thread.currentThread().getName());
    }
}
